<?php

namespace paper;

class Event
{
    private array $eventListeners;

    public const EVENT_EXCEPTION = 'system_event_exception';
    public const EVENT_ERROR = 'system_event_error';

    public function __construct()
    {

    }

    public function trigger(string $eventName, array $params = [])
    {
        if (in_array($eventName, $this->eventListeners)) {
            call_user_func_array($this->eventListeners[$eventName], $params);
        }
    }

    public function on($eventName, callable $listener)
    {
        $this->eventListeners[$eventName] = $listener;
    }
}